package com.yunqing.restkeeper.enterprise.web.controller.store;

import com.yunqing.restkeeper.enterprise.web.vo.store.AddDishCategoryVO;
import com.yunqing.restkeeper.store.api.entity.DishCategory;
import com.yunqing.restkeeper.store.api.service.IDishCategoryService;
import com.yunqing.restkeeper.web.common.response.vo.PageVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName DishCategoryController
 * @Description TODO
 * @author: puyunqing
 * @Date: 2025/7/23
 */
@Slf4j
@Tag(name = "分类管理")
@RestController
@RequestMapping("/dishCategory")
public class DishCategoryController {

    @DubboReference(version = "1.0.0", check = false)
    private IDishCategoryService dishCategoryService;

    @Operation(summary = "添加分类")
    @PostMapping("/add")
    public boolean add(@RequestBody AddDishCategoryVO addDishCategoryVO) {
        return dishCategoryService.add(addDishCategoryVO.getCategoryName(), addDishCategoryVO.getType());
    }

    /**
     * 修改分类名称
     *
     * @return
     */
    @Operation(summary = "修改分类")
    @PutMapping("/update/{id}")
    public boolean update(@PathVariable String id, @RequestParam(name = "categoryName") String categoryName) {
        return dishCategoryService.update(id, categoryName);
    }

    @Operation(summary = "分页列表")
    @Parameters({
            @Parameter(in = ParameterIn.PATH, name = "page", description = "当前页码", required = true, schema = @Schema(type = "Integer")),
            @Parameter(in = ParameterIn.PATH, name = "pageSize", description = "分页大小", required = true, schema = @Schema(type = "Integer"))})
    @GetMapping("/pageList/{page}/{pageSize}")
    public PageVO<DishCategory> findByPage(@PathVariable Integer page, @PathVariable Integer pageSize) {
        return new PageVO<>(dishCategoryService.queryPage(page, pageSize));
    }

    /**
     * 菜品，套餐分类下拉列表使用
     * 1 菜品 2 套餐
     *
     * @return
     */
    @Operation(summary = "添加分类")
    @GetMapping("/type/{type}")
    public List<Map<String, Object>> getByType(@PathVariable Integer type) {
        return dishCategoryService.findCategoryList(type);
    }
}
